package framework.util.easypoi;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用于辅助easypoi转换的类
 *
 * @author 吴宇亮
 * @date 2019年1月23日
 */
public class ExcelTransformHelper {

	public static final Map<String, Integer> isMap = new HashMap<>(2);

	static {
		isMap.put("否", 0);
		isMap.put("是", 1);
	}

	// 待转换的"下划线属性名"，如"_state"
	private String fieldName;
	// 用于给Stirng转Integer字段
	private Map<String, Integer> transformMap;

	/**
	 * 将clazz中以'_'前缀开头的属性全部添加到List<ExcelTransformHelper>中
	 *
	 * @param clazz
	 * @return
	 */
	public static List<ExcelTransformHelper> asList(Class<?> clazz){
		ArrayList<ExcelTransformHelper> list = new ArrayList<>(clazz.getDeclaredFields().length);
		for(Field field : clazz.getDeclaredFields()){
			if(field.getName().startsWith("_")){
				list.add(new ExcelTransformHelper(field.getName()));
			}
		}
		return list;
	}
	
	public static List<ExcelTransformHelper> asList(String... _fieldName){
		ArrayList<ExcelTransformHelper> list = new ArrayList<>(_fieldName.length);
		for (String fieldName : _fieldName) {
			list.add(new ExcelTransformHelper(fieldName));
		}
		return list;
	}
	
	public static List<ExcelTransformHelper> asIsList(String... _fieldName) {
		ArrayList<ExcelTransformHelper> list = new ArrayList<>(_fieldName.length);
		for (String fieldName : _fieldName) {
			list.add(new ExcelTransformHelper(fieldName, isMap));
		}
		return list;
	}

	public ExcelTransformHelper(String fieldName) {
		super();
		this.fieldName = fieldName;
	}

	public ExcelTransformHelper(String fieldName, Map<String, Integer> transformMap) {
		super();
		this.fieldName = fieldName;
		this.transformMap = transformMap;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public Map<String, Integer> getTransformMap() {
		return transformMap;
	}

	public void setTransformMap(Map<String, Integer> transformMap) {
		this.transformMap = transformMap;
	}

	


}
